package com.pms.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pms.framework.Action;

public class CommonAjaxAction implements Action {
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		String mode = (String) request.getParameter("mode");

		String responseStr = null;
		/*if (mode.equalsIgnoreCase("TaxForStudio")) {
			responseStr = getTaxTypes(request, response);
		}
		if (mode.equalsIgnoreCase("City")) {
			responseStr = getCities(request, response);
		}
		if (mode.equalsIgnoreCase("printJobData")) {
			responseStr = getPrintJobData(request, response);
		}
		if (mode.equalsIgnoreCase("printCharge")) {
			responseStr = getPrintCharge(request, response);
		}*/
		System.out.println("@@@@@@@@@@@@@ responseStr "+responseStr);
		request.setAttribute("responseStr",responseStr);
	}

	/*public String getTaxTypes(HttpServletRequest request, HttpServletResponse response) {
		String respText="";
		try{
			long studioId=JSPUtility.GetLong(request,"studioId",-1);

			TaxType[] taxtype= TaxTypeDao.getInstance().findSelectedTax(studioId);
			for (int i = 0; i < taxtype.length; i++) {
				if(i!=0){
					respText=respText+"&&"+taxtype[i].getName()+"&-&"+taxtype[i].getTaxTypeId();
				}else{
					respText=taxtype[i].getName()+"&-&"+taxtype[i].getTaxTypeId();
				}
			}

		}catch(Exception e){
			e.printStackTrace();
			System.out.println("Error "+e.getMessage());
		}
		return  respText;
	}
	public String getCities(HttpServletRequest request, HttpServletResponse response) {
		String respText="";
		try{
			//long userId=JSPUtility.GetLong(request,"userId",-1);
			long stateId=JSPUtility.GetLong(request,"stateId",-1);

			City[] city= CityDao.getInstance().findWhereStateIdEquals(stateId);
			for (int i = 0; i < city.length; i++) {
				if(i!=0){
					respText=respText+"&&"+city[i].getName()+"&-&"+city[i].getCityId();
				}else{
					respText=city[i].getName()+"&-&"+city[i].getCityId();
				}
			}

		}catch(Exception e){
			e.printStackTrace();
			System.out.println("Error "+e.getMessage());
		}
		return  respText;
	}
	public String getPrintJobData(HttpServletRequest request, HttpServletResponse response) {
		String strPrintFormats="";
		String strMediaType="";
		try{
			long studioId=JSPUtility.GetLong(request,"studioId",-1);
			long categoryId=JSPUtility.GetLong(request,"categoryId",-1);
			long printSize=JSPUtility.GetLong(request,"printSize",-1);

			PrintFormatType[] pFType=PrintFormatTypeDao.getInstance().findForPrintJobByPrintSize(studioId, printSize, categoryId);
			MediaTypeMaster[] mediaType =MediaTypeMasterDao.getInstance().findForPrintJobByPrintSize(studioId, printSize, categoryId);

			for (int i = 0; i < pFType.length; i++) {
				if(i!=0){
					strPrintFormats=strPrintFormats+"&&"+pFType[i].getName()+"&-&"+pFType[i].getPrintFormatTypeId();
				}else{
					strPrintFormats=pFType[i].getName()+"&-&"+pFType[i].getPrintFormatTypeId();
				}
			}


			for (int i = 0; i < mediaType.length; i++) {
				if(i!=0){
					strMediaType=strMediaType+"&&"+mediaType[i].getMediaType()+"&-&"+mediaType[i].getMediaTypeMasterId();
				}else{
					strMediaType=mediaType[i].getMediaType()+"&-&"+mediaType[i].getMediaTypeMasterId();
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("Error "+e.getMessage());
		}
		return  strPrintFormats+"^"+strMediaType;
	}
	public String getPrintCharge(HttpServletRequest request, HttpServletResponse response){

		double printAmount=0;
		double reprintAmount=0;
		try{
			long studioId=JSPUtility.GetLong(request,"studioId",-1);
			long categoryId=JSPUtility.GetLong(request,"categoryId",-1);
			long printSize=JSPUtility.GetLong(request,"printSize",-1);
			//long printFormat=JSPUtility.GetLong(request,"printFormat",-1);
			//long mediaType=JSPUtility.GetLong(request,"mediaType",-1);
			int rePrintType=JSPUtility.GetInt(request,"rePrintType",-1);

			//ConfigurePrintCharge printCharge= ConfigurePrintChargeDao.getInstance().findPrintConfigurationForPrintJob(studioId,categoryId,printSize,printFormat,mediaType);
			ConfigurePrintCharge printCharge= ConfigurePrintChargeDao.getInstance().findPrintConfigurationForPrintJob(studioId,categoryId,printSize);

			if(printCharge!=null){
				switch (rePrintType) {
				case ConfigurePrintCharge.STATUS_NORMAL:
					printAmount=printCharge.getRate();
					break;
				case ConfigurePrintCharge.STATUS_EXPRESS:
					printAmount=printCharge.getInstantRate();
					break;
				case ConfigurePrintCharge.STATUS_REPRINT:
					printAmount=printCharge.getReprintRate();
					break;
				default:
					printAmount=printCharge.getRate();
				break;
				}
			}
			reprintAmount=printCharge.getReprintRate();

		}catch(Exception e){
			e.printStackTrace();
			System.out.println("Error "+e.getMessage());
		}
		return  printAmount+"^"+reprintAmount;
	}*/
}
